package org.apache.rocketmq.common.thread;

import java.util.concurrent.ThreadPoolExecutor;

public class ThreadPoolQueueSizeMonitor implements ThreadPoolStatusMonitor{
    private int queueCapacity;
    public ThreadPoolQueueSizeMonitor(int queueCapacity) {
        this.queueCapacity = queueCapacity;
    }

    @Override
    public String describe() {
        return "queueSize";
    }


    @Override
    public double value(ThreadPoolExecutor executor) {
        return executor.getQueue().size();
    }

    @Override
    public boolean needPrintJstack(ThreadPoolExecutor executor, double value) {
        return executor.getQueue().size() > queueCapacity * 0.85;
    }
}
